﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.DestroyMobilePartyLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class DestroyMobilePartyLogEntry : LogEntry
  {
    [SaveableField(210)]
    public readonly Hero Hero;
    [SaveableField(211)]
    public readonly IFaction Faction;
    [SaveableField(212)]
    public readonly IFaction DestroyerPartyFaction;
    [SaveableField(213)]
    public readonly Hero DestroyerHero;
    [SaveableField(214)]
    private readonly TextObject _destroyerPartyName;

    internal static void AutoGeneratedStaticCollectObjectsDestroyMobilePartyLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Hero);
      collectedObjects.Add((object) this.Faction);
      collectedObjects.Add((object) this.DestroyerPartyFaction);
      collectedObjects.Add((object) this.DestroyerHero);
      collectedObjects.Add((object) this._destroyerPartyName);
    }

    internal static object AutoGeneratedGetMemberValueHero(object o)
    {
      return (object) ((DestroyMobilePartyLogEntry) o).Hero;
    }

    internal static object AutoGeneratedGetMemberValueFaction(object o)
    {
      return (object) ((DestroyMobilePartyLogEntry) o).Faction;
    }

    internal static object AutoGeneratedGetMemberValueDestroyerPartyFaction(object o)
    {
      return (object) ((DestroyMobilePartyLogEntry) o).DestroyerPartyFaction;
    }

    internal static object AutoGeneratedGetMemberValueDestroyerHero(object o)
    {
      return (object) ((DestroyMobilePartyLogEntry) o).DestroyerHero;
    }

    internal static object AutoGeneratedGetMemberValue_destroyerPartyName(object o)
    {
      return (object) ((DestroyMobilePartyLogEntry) o)._destroyerPartyName;
    }

    public DestroyMobilePartyLogEntry(MobileParty mobileParty, PartyBase destroyerParty)
    {
      MobileParty mobileParty1 = mobileParty;
      this.Hero = mobileParty1.LeaderHero;
      this.Faction = mobileParty1.MapFaction;
      this._destroyerPartyName = destroyerParty?.Name;
      this.DestroyerPartyFaction = destroyerParty?.MapFaction;
      this.DestroyerHero = destroyerParty?.LeaderHero;
    }

    public override int GetAsRumor(Settlement settlement, ref TextObject comment)
    {
      int asRumor = 0;
      if (this.DestroyerPartyFaction == settlement.MapFaction && this.DestroyerHero != null && this.Hero != null)
      {
        comment = new TextObject("{=shihxzUN}Praise be... {LORD.LINK} met {OTHER_SIDE} and whipped them soundly. Maybe now there will be an end to this war.");
        StringHelpers.SetCharacterProperties("LORD", this.DestroyerHero.CharacterObject, comment);
        comment.SetTextVariable("OTHER_SIDE", FactionHelper.GetTermUsedByOtherFaction(this.Faction, settlement.MapFaction, false));
        return 4;
      }
      if (this.Faction != settlement.MapFaction || this.DestroyerHero == null || this.Hero == null)
        return asRumor;
      comment = new TextObject("{=O4dWdKZd}Ach... So they say {LORD.LINK} got {?LORD.GENDER}his{?}her{\\?} arse handed to {?LORD.GENDER}him{?}her{\\?} by {OTHER_SIDE}. Grim times, friend.");
      StringHelpers.SetCharacterProperties("LORD", this.Hero.CharacterObject, comment);
      comment.SetTextVariable("OTHER_SIDE", FactionHelper.GetTermUsedByOtherFaction(this.DestroyerPartyFaction, settlement.MapFaction, false));
      return 4;
    }

    public override string ToString()
    {
      TextObject parent = TextObject.Empty;
      if (this.Hero != null && this._destroyerPartyName != null)
      {
        parent = new TextObject("{=i90Cmb5e}Party of {HERO.NAME} is destroyed by {DESTROYER_PARTY}");
        StringHelpers.SetCharacterProperties("HERO", this.Hero.CharacterObject, parent);
        parent.SetTextVariable("DESTROYER_PARTY", this._destroyerPartyName);
      }
      return parent.ToString();
    }
  }
}
